package users

import (
	"api/internal/respons"
	"api/internal/svc"
	"api/internal/types"
	"context"
	"user_srv/userclient"

	"github.com/zeromicro/go-zero/core/logx"
)

type MembershipRenewalLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewMembershipRenewalLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MembershipRenewalLogic {
	return &MembershipRenewalLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *MembershipRenewalLogic) MembershipRenewal(req *types.MembershipRenewalsRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	permissions, err := l.svcCtx.UserRpc.MembershipRenewal(l.ctx, &userclient.MembershipRenewalRequest{
		Price: req.Price,
	})
	if err != nil {
		return respons.Error(400, "续费失败", err.Error()), err
	}

	return respons.Success(permissions), nil
}
